import axios from 'axios'

// 公司相关接口
export function getCompanyList(params) {
    return axios.get('/api/users/companies/', {
        params,
        // 添加超时设置
        timeout: 10000,
        // 添加错误处理
        validateStatus: function (status) {
            return status >= 200 && status < 300; // 默认值
        }
    }).catch(error => {
        throw error;
    });
}

export function getCompanyById(id) {
    return axios.get(`/api/users/companies/${id}/`);
}

export function createCompany(data) {
    return axios.post('/api/users/companies/', data);
}

export function updateCompany(id, data) {
    return axios.put(`/api/users/companies/${id}/`, data);
}

export function deleteCompany(id) {
    return axios.delete(`/api/users/companies/${id}/`);
}

// 企业员工相关接口
export function getEmployeeList(params) {
    return axios.get('/api/users/company-employees/', {
        params,
        // 添加超时设置
        timeout: 10000,
        // 添加错误处理
        validateStatus: function (status) {
            return status >= 200 && status < 300;
        }
    }).catch(error => {
        throw error;
    });
}

export function getEmployeeById(id) {
    return axios.get(`/api/users/company-employees/${id}/`);
}

export function createEmployee(data) {
    return axios.post('/api/users/company-employees/', data);
}

export function updateEmployee(id, data) {
    return axios.put(`/api/users/company-employees/${id}/`, data);
}

export function deleteEmployee(id) {
    return axios.delete(`/api/users/company-employees/${id}/`);
}

// 获取指定公司的员工列表
export function getCompanyEmployees(companyId, params) {
    return axios.get(`/api/users/companies/${companyId}/employees/`, {
        params,
        // 添加超时设置
        timeout: 10000,
        // 添加错误处理
        validateStatus: function (status) {
            return status >= 200 && status < 300;
        }
    }).catch(error => {
        throw error;
    });
}

// 为指定公司创建员工
export function createCompanyEmployee(companyId, data) {
    return axios.post(`/api/users/companies/${companyId}/employees/`, data);
}

// 物业员工相关接口
export function getParkEmployeeList(params) {
    return axios.get('/api/users/profiles/park-employees/', {
        params,
        // 添加超时设置
        timeout: 10000,
        // 添加错误处理
        validateStatus: function (status) {
            return status >= 200 && status < 300;
        }
    }).catch(error => {
        throw error;
    });
}

export function getParkEmployeeById(id) {
    return axios.get(`/api/users/profiles/park-employees/${id}/`);
}

export function createParkEmployee(data) {
    return axios.post('/api/users/profiles/park-employees/', data);
}

export function updateParkEmployee(id, data) {
    return axios.put(`/api/users/profiles/park-employees/${id}/`, data);
}

export function deleteParkEmployee(id) {
    return axios.delete(`/api/users/profiles/park-employees/${id}/`);
}

// 访客相关接口
export function getVisitorList(params) {
    return axios.get('/api/users/visitors/', { params });
}

export function getVisitorById(id) {
    return axios.get(`/api/users/visitors/${id}/`);
}

export function createVisitor(data) {
    return axios.post('/api/users/visitors/', data);
}

export function updateVisitor(id, data) {
    return axios.put(`/api/users/visitors/${id}/`, data);
}

export function deleteVisitor(id) {
    return axios.delete(`/api/users/visitors/${id}/`);
} 
